﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

namespace Media
{
    /// <summary>
    /// Abstract generic class
    /// Used to get information about an unknown media file
    /// </summary>
    [Serializable]
    [System.Xml.Serialization.XmlInclude(typeof(PictureInfo))]
    [System.Xml.Serialization.XmlInclude(typeof(MusicInfo))]
    [System.Xml.Serialization.XmlInclude(typeof(MovieInfo))]
    public abstract class AMediaInfo
    {
        #region "Properties"
        protected TagLib.File file;
        public long Size { get; set; }
        public String BitRates { get; set; }
        public String Length {get; set;}
        public String Genre{get; set;}
        public String Year { get; set; }
        public String Album { get; set; }
        public String Author{get;set;}
        public String Track{get;set;}
        public String Title{get;set;}
        public String Dimension { get; set; }
        public String FilePath { get; set; }
        public String Format { get; set; }
        #endregion

        #region "Contructeurs"
        /// <summary>
        /// Serialization Constructor prefer AMediaInfo(String path, TagLib.File f)
        /// </summary>
        public AMediaInfo()
        {
            file = null;
            Title = null;
            Track = null;
            FilePath = null;
            Format = null;
            Dimension = null;
            Author = null;
            Album = null;
            Genre = null;
            Length = null;
            BitRates = null;
            Year = null;
            Size = 0;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="path">Path of the media file</param>
        /// <param name="f">file opened with taglib sharp</param>
        public AMediaInfo(String path, TagLib.File f)
        {
            if (path != null)
            {
                FileInfo fi = new FileInfo(path);
                if (fi != null)
                    Size = fi.Length;
            }
            else
                Size = 0;
            if (f != null)
            {
                file = f;
                if (f.Tag != null)
                    Year = f.Tag.Year.ToString();
                Format = f.MimeType;
            }
            else
            {
                file = null;
                Year = null;
            }
            Title = null;
            Track = null;
            FilePath = null;
            Dimension = null;
            Author = null;
            Album = null;
            Genre = null;
            Length = null;
            BitRates = null;
            FilePath = path;
        }
        #endregion

        #region "Getters / Setters"

        public void setSize(long size)
        {
            Size = size;
        }

        public long getSize()
        {
            return (Size);
        }

        public void setBitRates(String bit)
        {
            BitRates = bit;
        }

        public String getBitRates()
        {
            return (BitRates);
        }

        public void setLength(String len)
        {
            Length = len;
        }

        public String getLength()
        {
            return (Length);
        }

        public void setGenre(String gen)
        {
            Genre = gen;
        }

        public String getGenre()
        {
            return (Genre);
        }

        public void setYear(String year)
        {
            Year = year;
        }

        public String getYear()
        {
            return (Year);
        }

        public void setAlbum(String alb)
        {
            Album = alb;
        }

        public String getAlbum()
        {
            return (Album);
        }

        public void setAuthor(String aut)
        {
            Author = aut;
        }

        public String getAuthor()
        {
            return (Author);
        }

        public void setTrackNumber(String tra)
        {
            Track = tra;
        }

        public String getTrackNumber()
        {
            return (Track);
        }

        public void setDimension(String dim)
        {
            Dimension = dim;
        }

        public String getDimension()
        {
            return (Dimension);
        }

        public void setTitle(String tit)
        {
            Title = tit;
        }

        public String getTitle()
        {
            return (Title);
        }

        public void setFilePath(String fil)
        {
           FilePath = fil;
        }

        public String getFilePath()
        {
            return (FilePath);
        }

        public void setFormat(String form)
        {
            Format = form;
        }

        public String getFormat()
        {
            return (Format);
        }
        #endregion
    }
}
